<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Does Boost.Log support process forking?</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Log v2">
<link rel="up" href="../rationale.html" title="Rationale and FAQ">
<link rel="prev" href="why_not_log4j.html" title="Why not using hierarchy of loggers, like in log4j? Why not Boost.Log4j? Etc.">
<link rel="next" href="init_term_support.html" title="Does Boost.Log support logging at process initialization and termination?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_not_log4j.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="init_term_support.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="log.rationale.fork_support"></a><a class="link" href="fork_support.html" title="Does Boost.Log support process forking?">Does Boost.Log support process
      forking?</a>
</h3></div></div></div>
<p>
        No, currently Boost.Log does not support process forking (i.e. <code class="computeroutput"><span class="identifier">fork</span></code> call in UNIX systems). There are several
        issues with process forking, for instance:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            File sinks do not attempt to reopen log files or synchronize access to
            files between parent and child processes. The resulting output may be
            garbled.
          </li>
<li class="listitem">
            File collectors do not expect several processes attempting to collect
            log files to the same target directory. This may result in spurious failures
            at log file rotation.
          </li>
<li class="listitem">
            The <a class="link" href="../detailed/attributes.html#log.detailed.attributes.process_id" title="Current process identifier">current_process_id</a>
            attribute value will not update in the child process.
          </li>
<li class="listitem">
            In multithreaded applications, one can generally not guarantee that a
            thread is not executing some Boost.Log code while an other thread forks.
            Some Boost.Log resources may be left irreversibly locked or broken in
            the forked process. This reservation is not specific to Boost.Log, other
            libraries and even the application itself are susceptible to this problem.
          </li>
</ul></div>
<p>
        There may be other issues as well. It seems unlikely that support for forking
        will be added to Boost.Log any time soon.
      </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
          This does not preclude the <code class="computeroutput"><span class="identifier">fork</span></code>+<code class="computeroutput"><span class="identifier">exec</span></code> sequence from working. As long as
          the forked process doesn't try to use any of Boost.Log code, the process
          should be able to call <code class="computeroutput"><span class="identifier">exec</span></code>
          or a similar function to load and start another executable.
        </p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2007-2021 Andrey Semashev<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_not_log4j.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="init_term_support.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
